package com.hgd.evp.admin.rest;

import com.hgd.evp.admin.biz.EDepartBiz;
import com.hgd.evp.admin.entity.EDepart;
import com.hgd.evp.admin.vo.DeptTree;
import com.hgd.evp.common.utils.ObjectResultResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("eDepart")
@Log4j
@Api(tags = "部门管理")
public class EDepartController {
    @Autowired
    private EDepartBiz eDepartBiz;

    @PostMapping("/instance")
    @ApiOperation("添加菜单")
    public ObjectResultResponse<Void> addDepart(@RequestBody @ApiParam(value = "待添加对象") EDepart eDepart,
                                               BindingResult bindingResult) {
        log.info("/eDepart/instance==>添加部门");
        ObjectResultResponse<Void> oResult = new ObjectResultResponse<>();
        if (bindingResult.hasErrors()) {
            oResult.setStatus(400);
            oResult.setMessage(bindingResult.getAllErrors().get(0).getDefaultMessage());
            return oResult;
        }

        oResult = eDepartBiz.addEDepart(eDepart);
        return oResult;
    }

    @GetMapping("/tree")
    @ApiOperation("获取部门树")
    public List<DeptTree> eDepartTree() {
        log.info("/eDepart/tree==>获取部门树");
        return eDepartBiz.getDepartTree();
    }
}